package maquinavotar.view;

import java.util.ArrayList;
import maquinavotar.common.Candidate;
import maquinavotar.dao.CandidatesDAOImplXml;
import java.awt.Button;
import java.awt.Label;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import maquinavotar.MaquinaVotarApp;

public class InitialScreen extends JPanel {
    
    public InitialScreen(final MaquinaVotarApp app) {
        
        this.add(new Label("Ingrese tarjeta"));
        
        Button btn_vot = new Button("Ingresar tarj. votante");
        btn_vot.addMouseListener(new java.awt.event.MouseAdapter() {
                @Override
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    app.showScreen(1,0);
                }
            });
        this.add(btn_vot);
        
        Button btn_adm = new Button("Ingresar tarj. administrador");
        btn_adm.addMouseListener(new java.awt.event.MouseAdapter() {
                @Override
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    CandidatesDAOImplXml c = new CandidatesDAOImplXml();
                    app.cands = (ArrayList<Candidate>) c.loadCandidatos("data_io/candidatos.xml");
                    if(app.cands == null)
                        JOptionPane.showMessageDialog(null, "Error al cargar los candidatos.", "Carga de datos", JOptionPane.WARNING_MESSAGE);
                    else JOptionPane.showMessageDialog(null, "Carga de candidatos finalizada exitosamente.", "Carga de datos", JOptionPane.INFORMATION_MESSAGE);
                }
            });
        this.add(btn_adm);
    }

}
